<?php

class LoginView {
	private $name = 'name';
	private $password = 'password';
	private $Username = 'Username';
	private $PrivetUserName = 'PrivetUserName';
	private $Checkbox = 'Checkbox';
	private $Login = 'Login';
	private $Logout = 'Logout';
	private $m_metaTags = array();
	private $FirstName ='FirstName';
	private $LastName = 'LastName';
	private $YourNumber = 'YourNumber';
	private $Email ='Email';
	private $m_charset;
	/*
	 * retunerar sträng
	 */
	//genererar inloggnings formuläret
	public function DoLoginBox() {
		//setcookie(name, value, expire, path, domain);
		return "
 	<div id=content>
 		<form action='' method='get'>
	 		<fieldset id=this>
	 		 <div id=name>
	 		    <p>Name: <input type= text name='$this->name'/>
	 			</p>
	 			<p>Password:<input type= text name='$this->password'/>
	 			</p>
	 			<p><input type='submit' name='$this->Login' value=Login>
	 			Remember me:<input type=checkbox name='$this->Checkbox' value='Checkbox':/><p/>
	 		</div>
	 		</fieldset>
	 		<fieldset id=thi>
	 		<div id=nam>
 		        <p>FirstName: <input type= text name='$this->FirstName'/>
	 		    </p>
	 		    <p>LastName: <input type= text name='$this->LastName'/>
	 		    </p>
	 		    <p>YourNumber: <input type= text name='$this->YourNumber'/>
	 		    </p>
	 		    <p>Email: <input type= text name='$this->Email'/>
	 		    </p>
	 		    <p>Är du en ny användare registrera dig här</p>
	 			<p><input type='submit' name='this->Login' value='New User'><p/>
	 		</div>
	 	   </fieldset>
 		</form>
 	</div>";
	}

	//genererar utloggnings rutan
	public function DoLogoutBox() {
		return "<form action='' method='get' name='$this->Logout'> 
		<p><input type='submit' name='$this->Logout' value=Logout></p></form>";
	}

	//tar emott indata från formuläret
	public function GetUserName() {
		if (isset($_GET[$this -> name]) == true) {
			return $_GET[$this -> name];
		} 
		return FALSE;
	}
	
	//tar emott indata från formuläret
	public function GetPassword() {
		if (isset($_GET[$this -> password]) == true) {
			return $_GET[$this -> password];
		}
		return FALSE;
	}

	//kontrollerar om användaren har tryckt på loggin knappen
	public function TriedToLogIn() {
		if (isset($_GET[$this -> Login]) == true) {
			return true;
		} else {
			return false;
		}
	}

	//kontrollerar om användaren har tryckt på loggout knappen
	public function TriedToLogOut() {
		if (isset($_GET[$this -> Logout]) == true) {
			return true;
		} else {
			return FALSE;
		}
	}
	
	public function Cookielogin(){
		$this->setCookieAndCheckBox();
		if(isset($_COOKIE[$this -> Username])){
			return"<div id=contain><p>Nu är du inloggad!! Hej helena</p></div>";
		}
       elseif(!isset($_COOKIE[$this -> Username])){
			return "<div id=contain><p>Du har inte tillåtit cookie Helena</p></div>";
		}
		
	}

	public function setCookieAndCheckBox() {
		//hämtar användarnamnet och setname
		if (isset($_GET[$this -> Checkbox]) == TRUE) {
			
			setcookie($this -> Username, $_GET[$this -> name], time() + 3600);
			setcookie($this -> PrivetUserName, $_GET[$this -> password], time() + 3600);
		 
		 $_COOKIE[$this -> Username] = $_GET[$this -> name];	
		 $_COOKIE[$this -> PrivetUserName] = $_GET[$this -> password];	
		}
	}

	public function DeleteCookie() {
		setcookie($this -> Username, "", time() - 3600);
		setcookie($this -> PrivetUserName, "", time() - 3600);
	}

}
?>